var t = getApp();

Page({
    data: {
        Loadeddata: !1,
        myVideo: null,
        isPlaying: !1,
        ADDetails: {},
        duration: null,
        countdown: null,
        list: [],
        showReward: !1,
        redpack_amount: "",
        advertising_id: 0,
        isMuted: !1,
        page: 1
    },
    onLoad: function(t) {
        this.data.advertising_id = this.options.aid, this.data.page = this.options.page, 
        this.setData({
            showReward: !1
        }), this.getData();
    },
    changeMuted: function() {
        this.setData({
            isMuted: !this.data.isMuted
        });
    },
    clickADVideo: function() {
        this.setData({
            isPlaying: !0
        });
    },
    getData: function() {
        var a = this, i = {};
        this.options.id && 0 != this.options.id && (i.put_in_type = "video" == this.options.tag ? "2" : "1", 
        i.put_in_id = this.options.id), i.page = this.options.page, this.page = this.options.page || 1;
        var e = t.getNetAddresss("plugin.ad-serving.frontend.advertising.index.getList");
        t._postNetWork({
            url: e,
            data: i,
            success: function(i) {
                var e = i.data;
                if (1 == e.result) {
                    for (var s = e.data.list.data, n = 0; n < s.length; n++) if (s[n].id == a.data.advertising_id) {
                        s.splice(0, n), a.setData({
                            list: s
                        });
                        break;
                    }
                    a.current_page = e.data.list.current_page, a.last_page = e.data.list.last_page;
                } else wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                }), t._isTextEmpty(e.data) && wx.navigateBack({
                    delta: 1
                });
                a.getADDetails();
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    getADDetails: function() {
        var a = this, i = t.getNetAddresss("plugin.ad-serving.frontend.advertising.play.getAdvertisingVideoData");
        t._postNetWork({
            url: i,
            data: {
                advertising_id: this.data.advertising_id
            },
            success: function(t) {
                var i = t.data;
                1 == i.result ? a.setData({
                    ADDetails: i.data.has_one_advertising_apply
                }) : (wx.showToast({
                    title: i.msg,
                    icon: "none",
                    duration: 1500
                }), i.data.status && 1 == i.data.status ? wx.navigateBack({
                    delta: 2
                }) : a.nextADData());
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    nextADData: function() {
        this.data.list.splice(0, 1), 0 != this.data.list.length ? (this.setData({
            list: this.data.list,
            advertising_id: this.data.list[0].id,
            redpack_amount: "",
            showReward: !1
        }), this.getADDetails()) : wx.showModal({
            title: "提示",
            showCancel: !1,
            content: "广告已到底",
            success: function(t) {
                t.confirm && wx.navigateBack({
                    delta: 1
                });
            }
        });
    },
    cloneADs: function() {
        try {
            wx.navigateBack({
                delta: 1
            });
        } catch (t) {
            wx.reLaunch({
                url: "/packageG/index/index"
            });
        }
    },
    addAdsertisingBrowse: function(a) {
        var i = t.getNetAddresss("plugin.ad-serving.frontend.advertising.play.addAdsertisingBrowse");
        t._postNetWork({
            url: i,
            data: {
                advertising_id: this.data.advertising_id,
                action_type: a
            },
            success: function(t) {
                var a = t.data;
                1 != a.result && wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    bindloadedmetadata: function(t) {
        this.setData({
            duration: Math.ceil(t.detail.duration),
            countdown: Math.ceil(t.detail.duration),
            Loadeddata: !0
        });
    },
    bindtimeupdate: function(t) {
        this.setData({
            countdown: this.data.duration - Math.ceil(t.detail.currentTime)
        });
    },
    bindended: function(t) {
        this.redpackRewardAction();
    },
    bindpause: function(t) {
        this.setData({
            isPlaying: !1
        });
    },
    bindplay: function() {
        this.setData({
            isPlaying: !0,
            Loadeddata: !1
        }), this.addAdsertisingBrowse(1);
    },
    redpackRewardAction: function() {
        var a = this, i = t.getNetAddresss("plugin.ad-serving.frontend.advertising.play.redpackRewardAction");
        t._postNetWork({
            url: i,
            data: {
                advertising_id: this.data.advertising_id
            },
            success: function(t) {
                var i = t.data;
                1 == i.result ? a.setData({
                    redpack_amount: i.data.redpack_amount,
                    showReward: !0
                }) : (wx.showToast({
                    title: i.msg,
                    icon: "none",
                    duration: 1500
                }), a.nextADData());
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    getMore: function() {
        var a = this, i = {};
        this.options.id && 0 != this.options.id && (i.put_in_type = "video" == this.options.tag ? "2" : "1", 
        i.put_in_id = this.options.id), i.page = this.data.page;
        var e = t.getNetAddresss("plugin.ad-serving.frontend.advertising.index.getList");
        t._getNetWork({
            url: e,
            data: i,
            success: function(t) {
                var i = t.data;
                1 == i.result ? a.setData({
                    list: that.data.info.concat(i.data.list.data),
                    current_page: i.data.current_page,
                    last_page: i.data.last_page
                }) : wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var t = this.data.page + 1;
            this.setData({
                page: t
            }), this.getMore();
        }
    },
    onShareAppMessage: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        return t && (a = t), {
            title: "广告播放",
            path: "/packageH/Advertising/advertisingPlayPage/advertisingPlayPage?tag=video&id=" + this.options.id + "&page=" + this.options.page + "&aid=" + this.options.aid + "&mid=" + a
        };
    }
});